<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品id" prop="productId">
        <el-input
          v-model="queryParams.productId"
          placeholder="请输入产品id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品编码" prop="productCode">
        <el-input
          v-model="queryParams.productCode"
          placeholder="请输入产品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="测试结果" prop="testResult">
        <el-input
          v-model="queryParams.testResult"
          placeholder="请输入测试结果"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="测试时长" prop="testTime">
        <el-input
          v-model="queryParams.testTime"
          placeholder="请输入测试时长"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电流" prop="current">
        <el-input
          v-model="queryParams.current"
          placeholder="请输入电流"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电压" prop="voltage">
        <el-input
          v-model="queryParams.voltage"
          placeholder="请输入电压"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设定温度" prop="temperature">
        <el-input
          v-model="queryParams.temperature"
          placeholder="请输入设定温度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="震动时间" prop="shakeTime">
        <el-input
          v-model="queryParams.shakeTime"
          placeholder="请输入震动时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="震动频率" prop="shakeFrequency">
        <el-input
          v-model="queryParams.shakeFrequency"
          placeholder="请输入震动频率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="震动幅值" prop="shakeSize">
        <el-input
          v-model="queryParams.shakeSize"
          placeholder="请输入震动幅值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备id" prop="deviceId">
        <el-input
          v-model="queryParams.deviceId"
          placeholder="请输入设备id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createDate">
        <el-date-picker clearable
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="数据名称" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入数据名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="测试人" prop="testUesr">
        <el-input
          v-model="queryParams.testUesr"
          placeholder="请输入测试人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品型号id" prop="productModelId">
        <el-input
          v-model="queryParams.productModelId"
          placeholder="请输入产品型号id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划任务id" prop="taskPalnId">
        <el-input
          v-model="queryParams.taskPalnId"
          placeholder="请输入计划任务id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="组织机构id" prop="organizeorganazId">
        <el-input
          v-model="queryParams.organizeorganazId"
          placeholder="请输入组织机构id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="波形数据" prop="waveData">
        <el-input
          v-model="queryParams.waveData"
          placeholder="请输入波形数据"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['smart:smartproducttestalldata:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['smart:smartproducttestalldata:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['smart:smartproducttestalldata:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['smart:smartproducttestalldata:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="smartproducttestalldataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="产品id" align="center" prop="productId" />
      <el-table-column label="产品编码" align="center" prop="productCode" />
      <el-table-column label="测试结果" align="center" prop="testResult" />
      <el-table-column label="测试时长" align="center" prop="testTime" />
      <el-table-column label="电流" align="center" prop="current" />
      <el-table-column label="电压" align="center" prop="voltage" />
      <el-table-column label="设定温度" align="center" prop="temperature" />
      <el-table-column label="震动时间" align="center" prop="shakeTime" />
      <el-table-column label="震动频率" align="center" prop="shakeFrequency" />
      <el-table-column label="震动幅值" align="center" prop="shakeSize" />
      <el-table-column label="设备id" align="center" prop="deviceId" />
      <el-table-column label="创建时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="数据名称" align="center" prop="state" />
      <el-table-column label="测试人" align="center" prop="testUesr" />
      <el-table-column label="产品型号id" align="center" prop="productModelId" />
      <el-table-column label="计划任务id" align="center" prop="taskPalnId" />
      <el-table-column label="组织机构id" align="center" prop="organizeorganazId" />
      <el-table-column label="波形数据" align="center" prop="waveData" >
            <template slot-scope="{ row }">
                  <span v-if="row.waveData && row.waveData.length > 10">
                    <el-popover placement="top-start" title="waveData" width="80px" trigger="hover">
                     <div>{{ row.waveData }}</div>
                       <span slot="reference">
                          {{ row.waveData.substr(0, 10) + '...' }}
                       </span>
                   </el-popover>
                  </span>
                <span v-else>{{ row.modStr }}</span>
              </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['smart:smartproducttestalldata:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['smart:smartproducttestalldata:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产品测试数据集对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="产品id" prop="productId">
          <el-input v-model="form.productId" placeholder="请输入产品id" />
        </el-form-item>
        <el-form-item label="产品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入产品编码" />
        </el-form-item>
        <el-form-item label="测试结果" prop="testResult">
          <el-input v-model="form.testResult" placeholder="请输入测试结果" />
        </el-form-item>
        <el-form-item label="测试时长" prop="testTime">
          <el-input v-model="form.testTime" placeholder="请输入测试时长" />
        </el-form-item>
        <el-form-item label="电流" prop="current">
          <el-input v-model="form.current" placeholder="请输入电流" />
        </el-form-item>
        <el-form-item label="电压" prop="voltage">
          <el-input v-model="form.voltage" placeholder="请输入电压" />
        </el-form-item>
        <el-form-item label="设定温度" prop="temperature">
          <el-input v-model="form.temperature" placeholder="请输入设定温度" />
        </el-form-item>
        <el-form-item label="震动时间" prop="shakeTime">
          <el-input v-model="form.shakeTime" placeholder="请输入震动时间" />
        </el-form-item>
        <el-form-item label="震动频率" prop="shakeFrequency">
          <el-input v-model="form.shakeFrequency" placeholder="请输入震动频率" />
        </el-form-item>
        <el-form-item label="震动幅值" prop="shakeSize">
          <el-input v-model="form.shakeSize" placeholder="请输入震动幅值" />
        </el-form-item>
        <el-form-item label="设备id" prop="deviceId">
          <el-input v-model="form.deviceId" placeholder="请输入设备id" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createDate">
          <el-date-picker clearable
            v-model="form.createDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数据名称" prop="state">
          <el-input v-model="form.state" placeholder="请输入数据名称" />
        </el-form-item>
        <el-form-item label="测试人" prop="testUesr">
          <el-input v-model="form.testUesr" placeholder="请输入测试人" />
        </el-form-item>
        <el-form-item label="产品型号id" prop="productModelId">
          <el-input v-model="form.productModelId" placeholder="请输入产品型号id" />
        </el-form-item>
        <el-form-item label="计划任务id" prop="taskPalnId">
          <el-input v-model="form.taskPalnId" placeholder="请输入计划任务id" />
        </el-form-item>
        <el-form-item label="组织机构id" prop="organizeorganazId">
          <el-input v-model="form.organizeorganazId" placeholder="请输入组织机构id" />
        </el-form-item>
        <el-form-item label="波形数据" prop="waveData">
          <el-input v-model="form.waveData" placeholder="请输入波形数据" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSmartproducttestalldata, getSmartproducttestalldata, delSmartproducttestalldata, addSmartproducttestalldata, updateSmartproducttestalldata } from "@/api/smart/smartproducttestalldata";

export default {
  name: "Smartproducttestalldata",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品测试数据集表格数据
      smartproducttestalldataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productId: null,
        productCode: null,
        testResult: null,
        testTime: null,
        current: null,
        voltage: null,
        temperature: null,
        shakeTime: null,
        shakeFrequency: null,
        shakeSize: null,
        deviceId: null,
        createDate: null,
        state: null,
        testUesr: null,
        productModelId: null,
        taskPalnId: null,
        organizeorganazId: null,
        waveData: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询产品测试数据集列表 */
    getList() {
      this.loading = true;
      listSmartproducttestalldata(this.queryParams).then(response => {
        this.smartproducttestalldataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        productId: null,
        productCode: null,
        testResult: null,
        testTime: null,
        current: null,
        voltage: null,
        temperature: null,
        shakeTime: null,
        shakeFrequency: null,
        shakeSize: null,
        deviceId: null,
        createDate: null,
        state: null,
        testUesr: null,
        productModelId: null,
        taskPalnId: null,
        organizeorganazId: null,
        waveData: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加产品测试数据集";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getSmartproducttestalldata(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改产品测试数据集";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateSmartproducttestalldata(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSmartproducttestalldata(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除产品测试数据集编号为"' + ids + '"的数据项？').then(function() {
        return delSmartproducttestalldata(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('smart/smartproducttestalldata/export', {
        ...this.queryParams
      }, `smartproducttestalldata_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
